/*
 * Date         Author       Note
 * 2015.06.24   wzwz         旧规格参数文件
 * 2015.06.26   wzwz         字符串未清空bug
 * 2015.07.03   wzwz         翻针三角状态设置bug
 * 2015.07.03   wzwz         转换纱嘴零位脉冲为针数
 * 2015.07.15   wzwz         纱嘴补正参数
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <mh/common.h>
#include <mh/mh_knit.h>
#include "func.h"
#include "mhdef.h"

#pragma pack(1)
typedef struct
{
    short xzq1_len;
    short xzq2_len;
    short xzq3_len;
    short xzq4_len;
    short xzq_piece;
    short xzq_mode;
    short rock_mode;
    short rock_zero_dir;
    short language;
    short tran;
    short xzq_sect;
    short dumu_comp;
    short prob_dist;
    short ssection;
    short resv;
    short sinkdir;
    short dumu_len[4];
} MAC_OLD_PARAM;

typedef struct {
    short balance;                    //平衡值
    short yarn_left_out;
    short yarn_right_out;
    short high_pos;                   //最高位(勾线位)
    short safe_pos;                   //安全位
    short pos_for_roll_close;         //罗拉合上位置
    short hook_open_pos_for_roll;     //脱圈位(高罗拉)
    short speed_for_up_start;         //起底板上升初始速度
    short speed_for_up_quick;         //起底板上升加速速度
    short speed_for_up_slow;          //起底板上升减速速度
    short delay_for_hook_open;        //脱圈位滞后
    short scissor_times;              //剪刀次数
    short hook_open_pos_for_rab;      //脱圈位2(主拉布)
    short speed_for_drop_2safe_pos;   //降到安全位速度
    short reset_speed;                //起底板复位速度
    short speed_down_after_hook_open; //起底板下降脱圈速度
    short pos_for_down_slow;          //起底板下降减速位置
    short speed_for_down_slow;        //起底板下降减速速度
    short speed_for_roll_when_drop;   //落布时罗拉速度
    short wait_for_drop;              //落布等待时间
    short pos_for_up_quick;           //起底板上升加速位置
    short pos_for_up_slow;            //起底板上升减速位置
    short pos_for_up_wait;            //起底板上升等待位置
    short pos_for_rab_close;          //主拉布合上位置
    short rab_close_speed;            //主拉布合上速度
    short rab_open_speed;             //主拉布打开速度
    short cs_enable;                  //剪夹使能
    //
    short rsvd1[13];
    short test_lali;
    short cs_syn;                     //剪夹联动
    short rsvd2[22];
    short rsvd3[64];
    int board_state;
}BOARD_OLD_PARAM;

typedef struct {
    int motor_coder;
    int motor_drive_wheel;
    int motor_pass_wheel;
    int motor_belt;
    int motor_pitch;
    int rsvd1;
    int motor_elec_molecular;
    int motor_elec_denominator;
    int rsvd2[8];
    int rock_coder;
    int rock_drive_wheel;
    int rock_pass_wheel;
    int rock_pitch;
    int rsvd3[2];
    int rock_elec_molecular;//分子
    int rock_elec_denominator;
    int rsvd4[8];
    int roll_min;
    int roll_max;
    int rsvd5[14];
}SERVO_OLD_PARAM;

typedef struct
{
    struct
    {
        ushort Integer;
        ushort Float;
    } type;
    int size;
    int total_pulse;
    int zero_pulse;
    int lgrz;
    int lglz;
    union
    {
        int rgrz;
        int jt_inter;
    } xzq_jt;
    int rglz;
    int qdb_enable;
    int rock_speed;
    int sink_enable;
    int shake_level;
    int gauze_time;
    int cam_time;
    int xzq_time;
    int mac_no;
    int dumu_reset;
    int dumu_work;
    int xzq_2left_comp;
    int xzq_2right_comp;
    int inch_pulse;
    int max_speed;
    int cam_work;
    int sink_work;
    int right_jt_enable;
    int roll_mode;
    int xzq_resel; // 选针器重选
    int ll_compe; // 罗拉补偿
} SYS_OLD_PARAM;
typedef struct {
    int start_needle;
    int ret_len;
    int ext_piece_inter;
    int ext_piece_enable;
    ushort hd_end;
    ushort hd_start;
    int hd_num;
    int savescreen_time;
    int mac_low_speed;
    int mac_knot_speed;
    int mac_limit_speed;
    int knot_line;
    int auto_zero_cloth;
    int rab_percent;
    int left_feeder_enable;
    int right_feeder_enable;
    int yarn_feeder_mode;
    int board_mode;
    int board_yarn;
    int cam_lock;
    int mac_hollow_speed;
    int roll_speed;            //高罗拉正转速度
    int roll_reverse_speed;    //高罗拉反转速度
    int dumu_add_4stop;
    int rude_needle;
    //
    int probe_shield;
    int yarn_take_mode;
    int auto_hd_drop;
    int rsvd[21];
}WORK_OLD_PARAM;
#pragma pack()
/*
 *
 */
int ReadOldDmbzFile(const char *file, int dmbz[2][8])
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(dmbz, 16 * sizeof(int), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 *
 */
int ReadOldMacFile(const char *file, MAC_OLD_PARAM *data)
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(data, sizeof(MAC_OLD_PARAM), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 *
 */
int ReadOldHideFile(const char *file, int data[12][2])
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(data, 24 * sizeof(int), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 *
 */
int ReadOldBeforeFile(const char *file, short data[10][140])
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(data, 1400 * sizeof(short), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 * average of each 5 items
 */
static short GetAverageBefore(const short *p)
{
    return p[0] + p[1] + p[2] + p[3] + p[4] / 5;
}
/*
 *
 */
int ReadOldBoardFile(const char *file, BOARD_OLD_PARAM *data)
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(data, sizeof(BOARD_OLD_PARAM), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 *
 */
int ReadOldServoFile(const char *file, SERVO_OLD_PARAM *data)
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(data, sizeof(SERVO_OLD_PARAM), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 *
 */
int ReadOldRockFile(const char *file, short data[98])
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(data, 98 * sizeof(short), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 *
 */
int ReadOldSongShaFile(const char *file, uchar data[38])
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(data, 38 * sizeof(uchar), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 *
 */
int ReadOldWarnFile(const char *file, int *data)
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(data, sizeof(int), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 *
 */
int ReadOldSinkFile(const char *file, short data[66])
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(data, 66 * sizeof(short), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 *
 */
int ReadOldSysFile(const char *file, SYS_OLD_PARAM *data)
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(data, sizeof(SYS_OLD_PARAM), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 *
 */
int ReadOldWorkFile(const char *file, WORK_OLD_PARAM *data)
{
    FILE *fp = fopen(file, "r");
    if(!fp)
    {
        return MH_FILE_ERROR_OPEN;
    }
    if(fread(data, sizeof(WORK_OLD_PARAM), 1, fp) != 1)
    {
        fclose(fp);
        return MH_FILE_ERROR_READ;
    }
    fclose(fp);
    return 0;
}
/*
 *
 */
int ReadOldParamFile(const char *dir, struct MH_KNIT *knit_data)
{
    int i, j;
    int ret = 0;
    char file[MH_FILE_NAME_MAX_LEN] = {0};
    TurnOnMachine(knit_data, FALSE);
    //servo
    strcat(file, dir);
    strcat(file, "servo");
    SERVO_OLD_PARAM servo;
    ret = ReadOldServoFile(file, &servo);
    if(ret)
    {
        printf("Read old servo param %s: %d\n", file, ret);
    }
    else
    {
        MOTOR_DRIVE motor_drive;
        motor_drive.motor_coder = servo.motor_coder;
        motor_drive.motor_drive_wheel = servo.motor_drive_wheel;
        motor_drive.motor_pass_wheel = servo.motor_pass_wheel;
        motor_drive.motor_belt = servo.motor_belt;
        motor_drive.motor_pitch = servo.motor_pitch;
        motor_drive.motor_elec_molecular = servo.motor_elec_molecular;
        motor_drive.motor_elec_denominator = servo.motor_elec_denominator;
        SetMotorDriveData(knit_data, &motor_drive);

        ROCK_DRIVE rock_drive;
        rock_drive.rock_coder = servo.rock_coder;
        rock_drive.rock_drive_wheel = servo.rock_drive_wheel;
        rock_drive.rock_pass_wheel = servo.rock_pass_wheel;
        rock_drive.rock_pitch = servo.rock_pitch;
        rock_drive.rock_elec_molecular = servo.rock_elec_molecular;
        rock_drive.rock_elec_denominator = servo.rock_elec_denominator;
        SetRockDriveData(knit_data, &rock_drive);

        SetRabMinParam(knit_data, servo.roll_min);
        SetRabMaxParam(knit_data, servo.roll_max);
    }
    //sys param
    file[0] = 0;
    strcat(file, dir);
    strcat(file, "sysparam");
    SYS_OLD_PARAM sys;
    ret = ReadOldSysFile(file, &sys);
    if(ret)
    {
        printf("Read old sys param %s: %d\n", file, ret);
    }
    else
    {
        sprintf(file, "%d.%d", sys.type.Integer, sys.type.Float);
        float f = atof(file);
        SetInchType(knit_data, f);
        SetTotalNeedle(knit_data, sys.size * f);
        SetMacLeftCom(knit_data, sys.zero_pulse);
        SetMacRightCom(knit_data, sys.zero_pulse + sys.total_pulse);
        SetBeltPitchAdj(knit_data, sys.total_pulse);
        if(sys.total_pulse)
        {
            int n = sys.lgrz - sys.zero_pulse;
            n *= sys.size * f;
            n /= sys.total_pulse;
            SetLeftYarnRightCom(knit_data, n);
            n = sys.lglz - sys.zero_pulse;
            n *= sys.size * f;
            n /= sys.total_pulse;
            SetLeftYarnLeftCom(knit_data, n);
            n = sys.xzq_jt.rgrz - sys.zero_pulse;
            n *= sys.size * f;
            n /= sys.total_pulse;
            SetRightYarnRightCom(knit_data, n);
            n = sys.rglz - sys.zero_pulse;
            n *= sys.size * f;
            n /= sys.total_pulse;
            SetRightYarnLeftCom(knit_data, n);
        }
        SetBoardEnable(knit_data, sys.qdb_enable);
        SetRockSpeed(knit_data, sys.rock_speed);
        SetSinkEnable(knit_data, sys.sink_enable);
        SetFrontShakeSense(knit_data, sys.shake_level);
        if(sys.shake_level)
        {
            SetShakeEnable(knit_data, TRUE);
        }
        else
        {
            SetShakeEnable(knit_data, FALSE);
        }
        SetGauzeHighVoltage(knit_data, sys.gauze_time);
        SetCamHighVoltage(knit_data, sys.cam_time);
        SetSelectHighVoltage(knit_data, sys.xzq_time);
        SetMacNum(knit_data, sys.mac_no);
        SetDumuResetSpeed(knit_data, sys.dumu_reset);
        SetDumuWorkSpeed(knit_data, sys.dumu_work);
        SetSelectLeftCom(knit_data, sys.xzq_2left_comp);
        SetSelectRightCom(knit_data, sys.xzq_2right_comp);
        //inch_pulse;
        SetMacHighSpeed(knit_data, sys.max_speed);
        //SetCamWorkSpeed(knit_data, sys.cam_work);
        SetSinkWorkSpeed(knit_data, sys.sink_work);
        //SetRightHeadEnable(knit_data, sys.right_jt_enable);
        SetRabEnable(knit_data, sys.roll_mode != 1);
        SetRollEnable(knit_data, sys.roll_mode == 0 || sys.roll_mode == 1);
        SetSelectRepeatEnable(knit_data, sys.xzq_resel);
        //SetRollCom(knit_data, sys.ll_compe); //罗拉补偿
    }
    //work param
    file[0] = 0;
    strcat(file, dir);
    strcat(file, "workparam");
    WORK_OLD_PARAM work;
    ret = ReadOldWorkFile(file, &work);
    if(ret)
    {
        printf("Read old work param %s: %d\n", file, ret);
    }
    else
    {
        SetStartNeedle(knit_data, work.start_needle);
        SetMacRetLen(knit_data, work.ret_len);
        SetExtPieceInter(knit_data, work.ext_piece_inter);
        //SetExtPieceEnable(knit_data, work.ext_piece_enable);
        SetHangDingEnd(knit_data, work.hd_end);
        SetHangDingStart(knit_data, work.hd_start);
        SetHangDingTimes(knit_data, work.hd_num);
        SetSaveScreenTime(knit_data, work.savescreen_time);
        if(work.savescreen_time)
        {
            SetSaveScreenEnable(knit_data, TRUE);
        }
        else
        {
            SetSaveScreenEnable(knit_data, FALSE);
        }
        SetMacLowSpeed(knit_data, work.mac_low_speed);
        //SetMacKnotSpeed(knit_data, work.mac_knot_speed);
        SetMacMidSpeed(knit_data, work.mac_limit_speed);
        SetKnotWaitLine(knit_data, work.knot_line);
        SetAutoZeroCloth(knit_data, work.auto_zero_cloth);
        SetRabPercent(knit_data, work.rab_percent);
        SetLeftYarnFeederEnable(knit_data, work.left_feeder_enable);
        SetRightYarnFeederEnable(knit_data, work.right_feeder_enable);
        SetYarnFeederMode(knit_data, work.yarn_feeder_mode);
        SetBoardParamKnitMode(knit_data, work.board_mode);
        SetBoardParamGauze(knit_data, work.board_yarn);
        SetCamLock(knit_data, work.cam_lock);
        SetMacEmptySpeed(knit_data, work.mac_hollow_speed);
        //work.roll_speed;            //高罗拉正转速度
        //work.roll_reverse_speed;    //高罗拉反转速度
        SetDumuAddPercent(knit_data, work.dumu_add_4stop);
        SetSecondDumuCom(knit_data, work.rude_needle);
        //
        SetProbeShield(knit_data, work.probe_shield);
        SetTakeYarnMode(knit_data, work.yarn_take_mode);
        SetAutoHdDropEnable(knit_data, work.auto_hd_drop);
    }
    //song sha
    file[0] = 0;
    strcat(file, dir);
    strcat(file, "songsha");
    uchar songsha[38] = {0};
    ret = ReadOldSongShaFile(file, songsha);
    if(ret)
    {
        printf("Read old song sha param %s: %d\n", file, ret);
    }
    else
    {
        for(i = 0; i < 32; ++i)
        {
            SetYarnFeederSpeed(knit_data, i, songsha[i + 6]);
        }
        SetFeederStartWait(knit_data, (songsha[3] << 8) | songsha[2]);
    }
    //sink
    file[0] = 0;
    strcat(file, dir);
    strcat(file, "xksetting");
    short sink[66] = {0};
    ret = ReadOldSinkFile(file, sink);
    if(ret)
    {
        printf("Read old sink param %s: %d\n", file, ret);
    }
    else
    {
        for(i = 0; i < 4; ++i)
        {
            for(j = 0; j < 8; ++j)
            {
                SetRunSink(knit_data, i, j, sink[i * 8 + j]);
                SetRunSink(knit_data, i + 4, j, sink[(i + 4) * 8 + j + 2]);
            }
        }
        SetFrontSinkResetValue(knit_data, sink[32]);
        SetBackSinkResetValue(knit_data, sink[33]);
    }
    //warn mask
    file[0] = 0;
    strcat(file, dir);
    strcat(file, "warn_forbid");
    int warn;
    ret = ReadOldWarnFile(file, &warn);
    if(ret)
    {
        printf("Read old warn param %s: %d\n", file, ret);
    }
    else
    {
        SetAlarmMask(knit_data, warn);
        SetFrontSafeDoorAlarm(knit_data, FALSE);
        SetBackSafeDoorAlarm(knit_data, FALSE);
    }
    //dmbz
    file[0] = 0;
    strcat(file, dir);
    strcat(file, "dmad");
    int dmbz[2][8] = {{0}};
    ret = ReadOldDmbzFile(file, dmbz);
    if(ret)
    {
        printf("Read old dmbz %s: %d\n", file, ret);
    }
    else
    {
        for(i = 0; i < 2; ++i)
        {
            for(j = 0; j < 4; ++j)
            {
                SetSingleDmbz(knit_data, i, j, dmbz[0][i ? j : j + 4]);
                SetYarnDmbz(knit_data, i, j, dmbz[1][i ? j : j + 4]);
            }
        }
    }
    //mac param
    file[0] = 0;
    strcat(file, dir);
    strcat(file, "fixparam");
    MAC_OLD_PARAM mac_param;
    ret = ReadOldMacFile(file, &mac_param);
    if(ret)
    {
        printf("Read old mac param %s: %d\n", file, ret);
    }
    else
    {
        SetSelect1DistanceToMacLeft(knit_data, mac_param.xzq4_len);
        SetSelect2DistanceToMacLeft(knit_data, mac_param.xzq3_len);
        SetSelect3DistanceToMacLeft(knit_data, mac_param.xzq2_len);
        SetSelect4DistanceToMacLeft(knit_data, mac_param.xzq1_len);
        SetRockType(knit_data, mac_param.rock_mode);
        SetRockZeroDrt(knit_data, mac_param.rock_zero_dir);
        SetLanguage(knit_data, mac_param.language);
        //SetCamType(knit_data, mac_param.tran);
        SetSelectSect(knit_data, mac_param.xzq_sect);
        SetSelectArray(knit_data, mac_param.xzq_mode);
        SetSelectStartSect(knit_data, mac_param.ssection);
        SetSelectPiece(knit_data, ~mac_param.xzq_piece);
        //SetDumuComp(knit_data, mac_param.dumu_comp);
        SetProbeDistance(knit_data, mac_param.prob_dist);
        //mac_param.resv;
        SetSinkDrt(knit_data, mac_param.sinkdir);
        SetDumu1DistanceToMacLeft(knit_data, mac_param.dumu_len[3]);
        SetDumu2DistanceToMacLeft(knit_data, mac_param.dumu_len[2]);
        SetDumu3DistanceToMacLeft(knit_data, mac_param.dumu_len[1]);
        SetDumu4DistanceToMacLeft(knit_data, mac_param.dumu_len[0]);
    }
    //hd_param
    file[0] = 0;
    strcat(file, dir);
    strcat(file, "hdparam");
    int hide_param[12][2] = {{0}};
    ret = ReadOldHideFile(file, hide_param);
    if(ret)
    {
        printf("Read old hide param %s: %d\n", file, ret);
    }
    else
    {
        SetProbeShield(knit_data, hide_param[0][0]);
        SetTranDumuEnable(knit_data, hide_param[1][0]);
    }
    //before
    file[0] = 0;
    strcat(file, dir);
    strcat(file, "jtadv");
    short before[10][140] = {{0}};
    ret = ReadOldBeforeFile(file, before);
    if(ret)
    {
        printf("Read old before param %s: %d\n", file, ret);
    }
    else
    {
        for(i = 0; i < 2; ++i)
        {
            for(j = 0; j < 24; ++j)
            {
                short com = GetAverageBefore(i ? &before[1][j * 5] : &before[3][j * 5]);
                SetYarnStopCom(knit_data, i, j, com);
                com = GetAverageBefore(i ? &before[4][j * 5] : &before[5][j * 5]);
                SetMacBeforeCom(knit_data, i, j, com);
                com = GetAverageBefore(i ? &before[0][j * 5] : &before[2][j * 5]);
                SetYarnBeforeCom(knit_data, i, j, com);
                com = GetAverageBefore(i ? &before[8][j * 5] : &before[9][j * 5]);
                SetDumuBeforeCom(knit_data, i, j, com);
            }
        }
    }
    //board
    file[0] = 0;
    strcat(file, dir);
    strcat(file, "qdbsetting");
    BOARD_OLD_PARAM board;
    ret = ReadOldBoardFile(file, &board);
    if(ret)
    {
        printf("Read Old board param %s: %d\n", file, ret);
    }
    else
    {
        SetBoardParamBalance(knit_data, board.balance);
        SetYarnLeftOut(knit_data, board.yarn_left_out);
        SetYarnRightOut(knit_data, board.yarn_right_out);
        SetBoardParamHighPos(knit_data, board.high_pos);
        SetBoardParamSafePos(knit_data, board.safe_pos);
        SetBoardParamRollClosePos(knit_data, board.pos_for_roll_close);
        SetBoardParamRollHookOpenPos(knit_data, board.hook_open_pos_for_roll);
        SetBoardParamUpStartSpeed(knit_data, board.speed_for_up_start);
        SetBoardParamUpQuickSpeed(knit_data, board.speed_for_up_quick);
        SetBoardParamUpSlowSpeed(knit_data, board.speed_for_up_slow);
        SetBoardParamHookOpenDelay(knit_data, board.delay_for_hook_open);
        SetBoardParamScissorTimes(knit_data, board.scissor_times);
        SetBoardParamRabHookOpenPos(knit_data, board.hook_open_pos_for_rab);
        SetBoardParamToSafeSpeed(knit_data, board.speed_for_drop_2safe_pos);
        SetBoardParamResetSpeed(knit_data, board.reset_speed);
        SetBoardParamDownHookOpenSpeed(knit_data, board.speed_down_after_hook_open);
        SetBoardParamDownSlowPos(knit_data, board.pos_for_down_slow);
        SetBoardParamDownSlowSpeed(knit_data, board.speed_for_down_slow);
        SetBoardParamDropRollSpeed(knit_data, board.speed_for_roll_when_drop);
        SetBoardParamDropWaitTime(knit_data, board.wait_for_drop);
        SetBoardParamUpQuickPos(knit_data, board.pos_for_up_quick);
        SetBoardParamUpSlowPos(knit_data, board.pos_for_up_slow);
        SetBoardParamUpWaitPos(knit_data, board.pos_for_up_wait);
        SetBoardParamRabClosePos(knit_data, board.pos_for_rab_close);
        SetRabCloseSpeed(knit_data, board.rab_close_speed);
        SetRabOpenSpeed(knit_data, board.rab_open_speed);
        //board.cs_enable;                  //剪夹使能
        //board.test_lali;
        SetBoardParamCSSyn(knit_data, board.cs_syn);
        //board.board_state;
    }
    //rock
    short rock[98] = {0};
    file[0] = 0;
    strcat(file, dir);
    strcat(file, "rock");
    ret = ReadOldRockFile(file, rock);
    if(ret)
    {
        printf("Read old rock param %s: %d\n", file, ret);
    }
    else
    {
        for(i = 0; i < 16; ++i)
        {
            SetRockRightTranCom(knit_data, i, rock[i]);

        }
        SetRockLeftTranCom(knit_data, 0, rock[0]);
        SetRockLeftCom(knit_data, 0, rock[96]);
        SetRockRightCom(knit_data, 0, rock[96]);
        SetRockRightStarCom(knit_data, 0, rock[64] - (CM_PER_INCH * 1000.0 / GetInchType(knit_data)) / 2);
        for(i = 1; i < 16; ++i)
        {
            SetRockLeftTranCom(knit_data, i, rock[16 + i - 1]);
            SetRockRightCom(knit_data, i, rock[32 + i - 1]);
            SetRockLeftCom(knit_data, i, rock[48 + i - 1]);
            SetRockRightStarCom(knit_data, i, rock[64 + i]);
            SetRockLeftStarCom(knit_data, i, rock[80 + i - 1]);
        }
    }
    return ret;
}
